<template>
  <!-- 新建商机 -->
  <div>
    <el-dialog
      title="新建商机"
      :visible.sync="showDialog"
      width="30%"
      :before-close="close"
      :close-on-click-modal="false"
    >
      <!-- 内容 -->
      <div>
        <div style="font-weight: 700;">基本信息</div>
        <div style="margin-top: 20px;">
          <el-form ref="form" label-width="90px" :rules="rules" :model="form">
            <el-form-item label="姓名:" prop="name">
              <el-input v-model="form.name" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="手机号:" style="margin-top:-10px" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="性别:" style="margin-top:-10px" prop="sex">
              <el-radio v-model="form.sex" label="1">男</el-radio>
              <el-radio v-model="form.sex" label="0">女</el-radio>
            </el-form-item>
            <el-form-item label="微信:" style="margin-top:-10px" prop="weixin">
              <el-input v-model="form.weixin" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="QQ:" style="margin-top:-10px" prop="qq">
              <el-input v-model="form.qq" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="年龄:" style="margin-top:-10px" prop="age">
              <el-input v-model="form.age" type="Number" placeholder="请输入" />
            </el-form-item>
            <el-form-item label="地区:" style="margin-top:-10px" prop="provinces">
              <el-cascader
                v-model="form.provinces"
                size="large"
                :options="provinceAndCityData"
                placeholder="请选择活动区域"
              />
            </el-form-item>
            <el-form-item label="意向学科:" style="margin-top:-10px" prop="subject">
              <el-select v-model="form.subject" placeholder="请选择活动区域">
                <el-option label="Java" value="0" />
                <el-option label="前端" value="1" />
                <el-option label="人工智能" value="2" />
                <el-option label="大数据" value="3" />
                <el-option label="Python" value="4" />
                <el-option label="测试" value="6" />
                <el-option label="新媒体" value="7" />
                <el-option label="产品经理" value="8" />
                <el-option label="UI设计" value="9" />
              </el-select>
            </el-form-item>
            <el-form-item label="渠道来源:" style="margin-top:-10px" prop="channel">
              <el-radio v-model="form.channel" label="0">线上活动</el-radio>
              <el-radio v-model="form.channel" label="1">推广介绍</el-radio>
            </el-form-item>
            <el-form-item label="备注:" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入" />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getcomMerceOpportunity } from '@/api/comMerceFirst'
// 省市联动
import { provinceAndCityData } from 'element-china-area-data'
export default {
  props: {
    showDialog: {
      type: Boolean,
      required: false
    }
  },
  data() {
    return {
    //   dialogVisible: false
      radio: '',
      region: '',
      // 新增数据
      form: {
        name: '',
        phone: '',
        sex: '1',
        weixin: '',
        age: '',
        qq: '',
        subject: '',
        channel: '',
        provinces: '',
        remark: ''
      },
      // 省区二级联动
      provinceAndCityData,
      // 校验
      rules: {
        name: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
        phone: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
          { pattern: /^1[3456789]\d{9}$/, message: '手机号格式不正确', trigger: 'blur' }
        ],
        subject: [{ required: true, message: '意向学科不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    /**
     * 提交
     */
    submit() {
      // 兜底校验
      this.$refs.form.validate(async flag => {
        if (!flag) return
        // 调用接口
        const src = await getcomMerceOpportunity(this.form)
        console.log(src)
        // 成功提醒
        this.$message.success('添加成功')
        // 确定后关闭弹窗
        this.close()
        // 调用父组件的方法
        this.$parent.getList()
      })
    },
    /**
     * 关闭弹窗
     */
    close() {
      this.form = {
        name: '',
        phone: '',
        sex: '',
        weixin: '',
        age: '',
        qq: '',
        subject: '',
        channel: '',
        provinces: '',
        remark: ''
      }
      this.$emit('update:showDialog', false)
    }

  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog__header{
    background-color: #1890ff;
}
::v-deep .el-dialog__title{
    color: #fff;
    font-size: 16px;
}
::v-deep .el-dialog__close{
    color: #fff;
}
::v-deep .el-input__inner{
    width: 300px !important;
    height: 30px !important;
}
::v-deep .el-textarea .el-textarea__inner{
    width: 300px !important;
}
</style>
